package com.example.service.impl;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import com.example.domain.EmailEntity;
import com.example.domain.OAImgEntity;
import com.example.domain.common.Constants;
import com.example.domain.dh.CarDataEntity;
import com.example.domain.dh.OAMJEntity;
import com.example.mapper.DHMJMapper;
import com.example.mapper.OAImgMapper;
import com.example.service.DHService;
import com.example.service.EmailService;
import com.example.utils.EncodeUtils;
import com.example.utils.MyCacheUtils;
import com.example.utils.ZipDown;
import com.example.utils.config.DHConfig;
import com.example.utils.http.HttpsUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Transactional
@Slf4j
public class DHServiceImp implements DHService {
	
	@Autowired
	DHMJMapper dhmjMapper;
	@Autowired
	OAImgMapper imgMapper;
	@Autowired
	EmailService userService;
	
	/**
	 * 获取token信息
	 */
	@Override
	public String queryLoginToken() {
		if(MyCacheUtils.get(Constants.DHTOKEN)==null) {
			log.info("重新调用接口获取token");
			return queryLoginTokenByDH();
		}else {
			log.info("缓存中存在,直接从缓存获取token");
			return MyCacheUtils.get(Constants.DHTOKEN).toString();
		}
	}

	@Override
	public String queryCarToken() {
		if(MyCacheUtils.get(Constants.DHCARTOKEN)==null) {
			log.info("重新调用接口获取车辆管理token");
			String bm = "utf-8";
			// https的请求，直接调用目前存在问题，无ssl证书
			
			String getCarTokenUrl = "http://"+DHConfig.getUrl() + "/ipms/subSystem/generate/token?userName=system";
			System.out.println("getCarTokenUrl:" + getCarTokenUrl);
			String retMsg = null;
			try {
				retMsg = HttpsUtils.doGetNoHeader(getCarTokenUrl, bm);
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println("retMsg:" + retMsg);
			Map<String, Object> map = new HashMap<String, Object>();
			map = JSONObject.parseObject(retMsg);
			String token = map.get("data").toString();
			log.info("获取大华 车辆管理token:{},\n return:{}", getCarTokenUrl, token);
			 
//			String token = "1gOKfOcEq3K4bgEH5tLL/MZb3uZrWBqCITx3hOIeWk7g="; 
			MyCacheUtils.put(Constants.DHCARTOKEN, token, 1000*60*20);//毫秒数  token30分钟过期,程序设置20分钟过期
			return token;
		}else {
			String token = MyCacheUtils.get(Constants.DHCARTOKEN).toString();
			log.info("缓存中存在,直接从缓存获取车辆管理token:"+token);
			return token;
		}
	}
	
	
	/**
	 * 获取大华登录token,1.先调用接口获取公钥,2.在根据公钥获取token
	 */
	@Override
	public String queryLoginTokenByDH() {
		String bm = "utf-8";
		String getPublicKeyUrl = "http://"+DHConfig.getUrl()+"/WPMS/getPublicKey";
		String getPublicKeyParam = "{\"loginName\":\""+DHConfig.getUser()+"\"}";
		String retMsg = HttpsUtils.doPost(getPublicKeyUrl, getPublicKeyParam, bm);
		Map<String, Object> map = new HashMap<String, Object>();
		map = JSONObject.parseObject(retMsg);
		String publicKey = map.get("publicKey").toString();
		log.info("获取大华publicKey.url:{},param:{},\n return:{}",getPublicKeyUrl,getPublicKeyParam,publicKey);
		String pwd = DHConfig.getPass();
		String loginPass = EncodeUtils.encryptByPublicKey(publicKey,pwd);
		String geTokenUrl = "http://"+DHConfig.getUrl()+"/WPMS/login";
		String getTokenParam = "{\"loginName\":\""+DHConfig.getUser()+"\",\"loginPass\":\""+loginPass+"\"}";
		retMsg = HttpsUtils.doPost(geTokenUrl, getTokenParam, bm);
		map = JSONObject.parseObject(retMsg);
		String token = map.get("token").toString();
		log.info("获取大华token.url:{},param:{},\n return:{}",geTokenUrl,getTokenParam,token);
		MyCacheUtils.put(Constants.DHTOKEN, token, 1000*60*20);//毫秒数  token30分钟过期,程序设置20分钟过期
		return token;
	}

	@Override
	public List<OAMJEntity> getMJData(String requestId) {
		return dhmjMapper.getMJData(requestId);
	}

	@Override
	public String queryDHPersonByLoginId(String loginId) {
		String bm = "utf-8";
		String token = queryLoginToken();
		Map<String, Object> map = new HashMap<String, Object>();
		String url = "http://"+DHConfig.getUrl()+"/CardSolution/card/person/bycondition/combined?userId=1&userName=system&token="+token;
		String param = "{\"pageNum\":\""+1+"\",\"pageSize\":\""+10+"\",\"code\":\""+loginId+"\"}";
		String retMsg = HttpsUtils.doPost(url, param, bm);
		System.out.println("结果："+retMsg);
		map = JSONObject.parseObject(retMsg);
		String dataJson = map.get("data").toString();
		map = JSONObject.parseObject(dataJson);
		log.info("查询大华用户信息是否已经存在.url:{},param:{},return:{}",url,param,map.get("totalRows"));
		return map.get("totalRows").toString();
	}

	@Override
	public String addDHPerson(String jsonParam) {
		String bm = "utf-8";
		String token = queryLoginToken();
		String url = "http://"+DHConfig.getUrl()+"/CardSolution/card/person?userId=1&userName=system&token="+token;
		String retMsg = HttpsUtils.doPost(url, jsonParam, bm);
		log.info("调用大华接口新增人员信息.url:{},param:{},return:{}",url,jsonParam,retMsg);
		return retMsg;
	}
	
	@Override
	public String queryDataByCarid(String carid) {
		String bm = "utf-8";
		String token = queryCarToken();
		System.out.println("获取到的carToken:"+token);
		Map<String, Object> map = new HashMap<String, Object>();
		token = JSONObject.parseObject(token).get("accessToken").toString();
		String url = "http://"+DHConfig.getUrl()+"/ipms/car/list?carNumLikeStr="+carid;
		String retMsg = null;
		
		try {
			retMsg = HttpsUtils.doGetSetHeader(url, bm, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
		map = JSONObject.parseObject(retMsg);
		String dataJson = map.get("data").toString();
		map = JSONObject.parseObject(dataJson);
		dataJson = map.get("pageData").toString();
		log.info("大华反馈的车辆相关信息:"+retMsg);
//		carNum: 车牌号  owner: 姓名
		List<CarDataEntity> list = JSONObject.parseArray(dataJson).stream()
				.map(item -> {
					CarDataEntity carDataEntity = JSONObject.parseObject(item.toString(), CarDataEntity.class);
					String workCode = carDataEntity.getOwnerCode();
					EmailEntity oaEntity = userService.queryOAPersonByWorkcode(workCode);
					if(oaEntity != null) {
						carDataEntity.setDh(oaEntity.getMobile());
						String gender = oaEntity.getGender();
						if(Double.parseDouble(gender) == 1) {
							gender = "男";
						} else if(Double.parseDouble(gender) == 2) {
							gender = "女";
						} else {
							gender = "";
						}
						carDataEntity.setXb(gender);
					}
					return carDataEntity;
					})
//				.filter(item -> StringUtils.isNotBlank(item.getDh()))
				.collect(Collectors.toList());
		
		return JSONObject.toJSONString(list);
	}
	
	@Override
	public String queryDataByBillid(String billid) {
		String filePath = queryBillImgDataUrl(billid);
		System.out.println("===========================文件路径:\n"+filePath);
		String cardid = "";
		return queryDataByCarid(cardid);
	}
	
	@Override
	public String ocrImgData(String img) {
		return ocrImgUrl(img);
	}
	
	private String queryBillImgDataUrl(String billid) {
		OAImgEntity imgEntity = imgMapper.queryBillImgData(billid);
		
		String filerealpath = imgEntity.getFilerealpath();
		String iszip = imgEntity.getIszip();
		String imagefilename = imgEntity.getImagefilename();
		String houzui = imagefilename.substring(imagefilename.lastIndexOf(".") + 1);
		System.out.println("iszip:"+iszip+"...0：未压缩 ， 1： 压缩");
		if ("1".equals(iszip)) {
			File zipfile = new File(filerealpath);
			filerealpath = ZipDown.unZip(zipfile, "/tmp/", "." + houzui);
		} else {
			File f=new File(filerealpath);
			int length = (int) f.length();
	        byte[] data = new byte[length];
	        try {
				new FileInputStream(f).read(data);
			} catch (Exception e) {
				e.printStackTrace();
			}
	        System.out.println(data.length);
//			filerealpath = ZipDown.copyFile(filerealpath, "/tmp/", "." + houzui);
		}
		return filerealpath;
	}
	
	// 参考 https://cloud.baidu.com/apiexplorer/index.html?Product=GWSE-DJAQ8YwekkQ&Api=GWAI-nPaigUrgq8i
	public static String ocrImgUrl(String imgUrl) {
		String path = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        // 设置query参数
        request.addQueryParameter("access_token", "24.6f831a3bc91d425fdf8d855bb1b9cfb2.2592000.1648715032.282335-25018281");
        // 设置jsonBody参数
        String jsonBody = "url="+imgUrl;
        request.setJsonBody(jsonBody);
        
        ApiExplorerClient client = new ApiExplorerClient();
        try {
          ApiExplorerResponse response = client.sendRequest(request);
          // 返回结果格式为Json字符串
          return response.getResult();
        } catch (Exception e) {
          e.printStackTrace();
        }
		return null;
	}
	
	public static String ocrImgBase64(String img) {
		String path = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        // 设置query参数
        request.addQueryParameter("access_token", "24.6f831a3bc91d425fdf8d855bb1b9cfb2.2592000.1648715032.282335-25018281");
        // 设置jsonBody参数
        String jsonBody = "image="+img;
        request.setJsonBody(jsonBody);
        
        ApiExplorerClient client = new ApiExplorerClient();
        try {
          ApiExplorerResponse response = client.sendRequest(request);
          // 返回结果格式为Json字符串
          return response.getResult();
        } catch (Exception e) {
          e.printStackTrace();
        }
		return null;
	}
	
	public static void main(String[] args) {
//		String resultStr = ocrImgUrl("http://localhost:9000/api/excel/33.jpg");
//		System.out.println("反馈结果："+resultStr);
//		if(resultStr == null) {
//			System.out.println("识别异常");
//		} else if(resultStr.contains("words_result")){
//			System.out.println("识别成功，反馈结果："+resultStr);
//		} else {
//			System.out.println("未识别出文字："+resultStr);
//		}
		
//		String imgBase64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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YJzgGBpaNToe3chCFHZGsmIa0a8wk0aSABuuhCEHPd1M2UXvZJG0Obrw4oQgJNmAQNSCfsRLduUA6IQgGzNDXC3Byc1gs61xl3WQhABbcNJJJ70wEgacyUIQhJazgb66JnAG+vNCEArAHsIO4nclMbQ0DtCEICQRtJLTcjXemMaM5J1LTYXQhCD5Whr2EC+Ya3SZRdot8lCEA4xNzFCEIQ/9k=";
//		convertBase64ToImage(imgBase64);
//		String resultStr1 = ocrImgBase64(imgBase64);
//		System.out.println("反馈结果："+resultStr1);
//		if(resultStr1 == null) {
//			System.out.println("识别异常");
//		} else if(resultStr1.contains("words_result")){
//			System.out.println("识别成功，反馈结果："+resultStr1);
//		} else {
//			System.out.println("未识别出文字："+resultStr1);
//		}
		
	}
	
	public static void convertBase64ToImage(String base64Code){
        BufferedImage image = null;
        byte[] imageByte = null;
        try {
            imageByte = DatatypeConverter.parseBase64Binary(base64Code);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            image = ImageIO.read(new ByteArrayInputStream(imageByte));
            bis.close();
            File outputfile = new File("D:\\download\\logs\\test\\sealImg.jpg");
            ImageIO.write(image, "jpg", outputfile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
}

